//
//  XGFocusView.m
//  BSBuDeJie
//
//  Created by monkey on 2019/1/4.
//  Copyright © 2019 itcast. All rights reserved.
//

#import <Masonry/Masonry.h>

#import "XGFocusView.h"

#import "XGLoginRegisterViewController.h"

@implementation XGFocusView

#pragma mark - 构造方法

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        [self setUpUI];
    }
    
    return self;
}

- (void)setUpUI
{
    // 创建子控件
    UIImageView *iconImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"header_cry_icon"]];
    UILabel *tipLabel = [UILabel labelWithText:@"快快登录吧，关注百思最in牛人\n好友动态让你过把瘾儿~\n欧耶~!" textColor:[UIColor purpleColor] font:15 textAlignment:NSTextAlignmentCenter];
    UIButton *loginRegisterButton = [UIButton buttonWithTitle:@"登录" fontSize:25 titleColor:[UIColor redColor] backgroundImageName:@"friendsTrend_login" highlightedBackgroundImageName:@"friendsTrend_login_click" target:self action:@selector(loginAction)];
    
    // 添加子控件
    [self addSubview:iconImageView];
    [self addSubview:tipLabel];
    [self addSubview:loginRegisterButton];
    
    // 设置自动布局
    [tipLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self);
    }];
    
    [iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(tipLabel.mas_centerX);
        make.bottom.equalTo(tipLabel.mas_top).offset(-30);
    }];
    
    [loginRegisterButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(tipLabel.mas_centerX);
        make.top.equalTo(tipLabel.mas_bottom).offset(30);
    }];
}

#pragma mark - 事件监听

- (void)loginAction
{
    XGLoginRegisterViewController *loginRegisterViewController = [[XGLoginRegisterViewController alloc] init];
    [[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:loginRegisterViewController animated:YES completion:nil];
}


@end
